package cn.jwm.permission.service.impl;


import cn.jwm.base.service.impl.BaseServiceImp;
import cn.jwm.dto.RolePermissionDTO;
import cn.jwm.permission.domain.Role;
import cn.jwm.permission.mapper.RoleMapper;
import cn.jwm.permission.query.RoleQuery;
import cn.jwm.permission.service.IRoleService;
import cn.jwm.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
@Service
public class RoleServiceImpl extends BaseServiceImp<Role> implements IRoleService {

    @Resource
    private RoleMapper roleMapper;


    @Transactional
    @Override
    public void deleteById(Long id) {
        roleMapper.delete(id);
    }




    @Override
    public void saveRolePermission(RolePermissionDTO dto) {

        roleMapper.deletePermissionByRoleId(dto.getRoleId());


        roleMapper.batchSaveRolePermission(dto.getRoleId(),dto.getPermissionSns());
    }

    @Override
    public List<String> getRolePermissionSns(Long roleId) {
        return roleMapper.getRolePermissionSns(roleId);
    }
}
